<template>
  <div style="background:#ffffff;">
    <el-row class="top_row">
      <el-col :span="24">
        <div class="top_title">
          <div class="left_add">
            <el-button
              type="danger"
              @click="$router.push('/Notice/Edit')"
              size="mini"
              icon="el-icon-circle-plus"
            >新增</el-button>
          </div>
          <div class="right_sel">
            <el-input size="mini" v-model="SelName" placeholder="查找...">
              <el-button slot="append" @click="SelDt" icon="el-icon-search" style="width:50px;"></el-button>
            </el-input>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-table :data="NoticeListInfo.NoticeList" style="width: 100%" height="500">
      <el-table-column prop="pk_Notice" label="ID" min-width="100" width="100" fixed="left"></el-table-column>
      <el-table-column prop="TypeName_CHS" label="类型" width="130"></el-table-column>
      <el-table-column prop="Title" label="标题" min-width="220"></el-table-column>
      <el-table-column prop="CreateDate" label="发布时间" width="190">
        <template slot-scope="scope">
          <span>{{scope.row.CreateDate|TimeFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="FullName" label="发布人" width="130"></el-table-column>
      <el-table-column prop="DepartmentName" label="部门" width="140"></el-table-column>
      <el-table-column prop="StatusName_CHS" label="状态" width="120">
        <template slot-scope="scope">
          <el-tag effect="dark" size="small" :style="'border:none;background:'+scope.row.Visual">{{ scope.row.StatusName_CHS }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="IsTop" label="置顶">
        <template slot-scope="scope">
          <el-checkbox :checked="scope.row.IsTop" :disabled="true">置顶</el-checkbox>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" min-width="200" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            @click="Edit(scope.row.pk_Notice)"
            class="el-icon-edit-outline"
            size="mini"
          >修改</el-button>
          <el-popconfirm
                @onConfirm="Delete(scope.$index,scope.row.pk_Department)"
                style="margin-left:10px;"
                title="确定删除此公告?">
                <el-button slot="reference" type="danger" size="mini" icon="el-icon-delete">删除</el-button>
              </el-popconfirm>
        </template>
          
        <!-- <el-button size="mini" type="danger" class="el-icon-delete" >删除</el-button> -->
      </el-table-column>
    </el-table>
    <div>
      <div style="padding:10px 0;text-align:center">
        <el-pagination
          background
          layout="prev, pager, next"
          :current-page.sync="page"
          :page-size="5"
          :total="NoticeListInfo.NoticeCount"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.top_row {
  border-bottom: 1px solid #f7f7f7;
  padding-bottom: 10px;
  .top_title {
    .left_add {
      float: left;
    }
    .right_sel {
      float: right;
    }
  }
}
</style>
<script>
export default {
  data() {
    return {
      NoticeListInfo: [],
      SelName: "",
      page: 1,
    };
  },
  mounted() {
    this.SelDt();
  },
  methods: {
    //判断添加或查询
    SelDt() {
      this.$axios({
        url: "/HrApi/NoticeList/GetNoticeList",
        method: "GET",
        params: {
          page: this.page,
          limit: 5,
          SelName: this.SelName,
          pk_User: this.$store.state.UserInfo.pk_User,
        },
      }).then((res) => {
        if (!res.data.code) {
          this.NoticeListInfo = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    //跳转
    Edit(id) {
      this.$router.push({
        path: "/Notice/Edit",
        query: {
          pk_Name: id,
        },
      });
    },
    Delete(index,pk_Department){
      his.$axios({
        url: '/HrApi/Car/DeleteCarInfo',
        method: 'POST',
        data: this.$Qs.stringify({
            pk_Department:pk_Department,
            pk_User:this.$store.state.UserInfo.pk_User
          })
      }).then(res => {
        if (!res.data.code) {
          this.$message.success(res.data.msg)
          this.SelDt();
        } else {
          this.$message.error(res.data.msg)
        }
      })
    }
  },
  //监听
  watch: {
    page(n) {
      this.SelDt();
    },
  },
  //格式化时间
  filters: {
    TimeFilter(t) {
      if (t === null) {
        return "无";
      }
      let dt = t.split("T").join(" ");
      if (dt.split(".").length > 1) {
        dt = dt.split(".")[0];
      }
      return dt;
    },
  },
};
</script>